<template>
  <div class="manager-list-tab-panel">
    <el-form ref="form" :model="form" label-width="0px">
      <div class="tx-tab" style="margin: 15px 0 0" v-if="tabs.list.length && !$currentUserInfo">
        <el-tabs
          v-model="tabs.active"
          @tab-click="changeTab"
          v-if="getParameter('menuId') == '1000000012' || getParameter('menuId') == '1000000014'"
        >
          <el-tab-pane
            v-for="(item, i) in tabs.list"
            :key="i"
            :name="item.name"
          >
            <div slot="label" class="tx-tab__label">
              {{ item.label }} ({{ item.mount }})
              <!-- <div class="tx-tab__number" v-if="item.mount && item.mount > 0">
                <div>{{ item.mount }}</div>
              </div> -->
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>

      <div v-if="!$currentUserInfo" style="height:30px">
        <tx-button-add :name="$dictValue('新增{name}')" @click="handleNew()" v-if="getParameter('menuId') != '1000000012' || (getParameter('menuId') == '1000000012')&&tabs.list.length"/>
        <div class="btnbox-right">
          <tx-button-add
            :icon="allowSort ? '' : 'el-icon-tickets'"
            :name="allowSort ? '保存排序' : '修改排序'"
            @click="updateSort"
          />
          <el-tooltip
            v-if="!allowSort"
            class="item"
            effect="dark"
            content="点击后进入修改排序模式，用户可以自行手动拖拽调整"
            placement="bottom-start"
          >
            <div class="tooltip"></div>
          </el-tooltip>
          <tx-button-add
            v-if="allowSort"
            icon=""
            name="取消排序"
            class="dialog-cancel-btn"
            style="background: #1d3f6a"
            @click="cancelSort"
          />
        </div>
      </div>
      <div
        v-else
        style="
          padding-bottom: 10px;
          display: flex;
          align-items: center;
          color: #fff;
        "
      >
        <span style="flex: 1">当前位置：{{ this.stepsLocationName }}</span>
        <div class="btnbox-right">
          <tx-button-add icon="" name="返回上一级" @click="handlePreLevel" />
        </div>
      </div>

      <div class="tx-tab" style="margin: 15px 0 0" v-if="tabs.list.length && $currentUserInfo">
        <el-tabs
          v-model="tabs.active"
          @tab-click="changeTab"
          v-if="getParameter('menuId') == '1000000012' || getParameter('menuId') == '1000000014'"
        >
          <el-tab-pane
            v-for="(item, i) in tabs.list"
            :key="i"
            :name="item.name"
          >
            <div slot="label" class="tx-tab__label">
              {{ item.label }} ({{ item.mount }})
              <!-- <div class="tx-tab__number" v-if="item.mount && item.mount > 0">
                <div>{{ item.mount }}</div>
              </div> -->
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>

      <tx-list-table
        :table="table"
        ref="listTable"
        row-key="index"
        v-loading="table.loading"
      >
        <tx-table-column-text label="排序" width="60">
          <template slot-scope="scope"
            ><span class="number-index">{{
              scope.scope.scope.$index + 1
            }}</span></template
          >
        </tx-table-column-text>
        <!-- 专家字段 -->
        <column
          :rules="formRules"
          :content="content"
          :label="$dictValue('{name}姓名')"
          field="name"
          showKey="expertName"
        />
        <tx-table-column-text
          :label="$dictValue('{name}类型')"
          v-if="show('expertSourceType')"
        >
          <template slot-scope="scope">
            <tx-table-select
              :entity="scope.row"
              name="sourceType"
              :rules="formRules.sourceType"
              :prop="buildRowProp(scope, 'sourceType')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请输入{name}类型')"
              :options="{ values: pageData.sourceType }"
              type="arra"
            />
          </template>
        </tx-table-column-text>
        <column
          :rules="formRules"
          :content="content"
          label="联系电话"
          field="phone"
          showKey="expertPhone"
        />
        <column
          :rules="formRules"
          :content="content"
          label="所在单位"
          field="workUnit"
          showKey="expertWorkUnit"
        />
        <column
          :rules="formRules"
          :content="content"
          label="单位地址"
          field="officeAddress"
          showKey="expertOrgAddress"
        />
        <tx-table-column-text
          label="专家级别"
          v-if="show('expertUserLevel')"
        >
          <template slot-scope="scope">
            <tx-table-select
              :entity="scope.row"
              name="userLevel"
              :rules="formRules.userLevel"
              :prop="buildRowProp(scope, 'userLevel')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请输入专家级别')"
              :options="{ values: pageData.expertUserLevel}"
              type="arra"
            />
          </template>
        </tx-table-column-text>
        <tx-table-column-text label="职称级别" v-if="show('expertJobLevel')">
          <template slot-scope="scope">
            <tx-table-select
              :entity="scope.row"
              name="jobLevel"
              :rules="formRules.jobLevel"
              :prop="buildRowProp(scope, 'jobLevel')"
              :action="scope.row.$action"
              placeholder="请输入职称级别"
              :options="{
                values: pageData.expertJobLevel,
              }"
              type="arra"
            />
          </template>
        </tx-table-column-text>
        <column
          :rules="formRules"
          :content="content"
          label="职务"
          field="job"
          showKey="expertJob"
        />
        <column
          :rules="formRules"
          :content="content"
          label="特长描述"
          field="desc"
          showKey="expertDesc"
        />

        <!-- 救援队伍 -->
        <column
          :rules="formRules"
          :content="content"
          :label="$dictValue('{name}名称')"
          field="orgName"
          showKey="jydwOrgName"
        />
        <!-- <tx-table-column-text label="救援队伍名称" v-if="show('jydwOrgName')">
          <template slot-scope="scope">
            <tx-table-input
              :entity="scope.row"
              name="orgName"
              :rules="formRules.orgName"
              :prop="buildRowProp(scope, 'orgName')"
              :action="scope.row.$action"
              placeholder="请输入队伍名称"
            />
          </template>
          </tx-table-column-text>
          <tx-table-column-text label="" width="0" v-if="show('jydwOrgName')">
          <template> </template>  
          </tx-table-column-text>> -->
        <tx-table-column-text
          label="救援队伍级别"
          v-if="show('jydwSourceLevel')"
        >
          <template slot-scope="scope">
            <column-jydw-source-level
              :row="scope.row"
              :rules="formRules"
              :content="content"
              :label="$dictValue('{name}级别')"
              field="sourceLevel"
              showKey="jydwSourceLevel"
            />
          </template>
        </tx-table-column-text>
        <!-- <tx-table-column-text
          label="救援队伍类型"
          v-if="show('jydwSourceType')"
        >
          <template slot-scope="scope">
            <column-jydw-source-type
              :row="scope.row"
              :rules="formRules"
              :content="content"
              :label="$dictValue('{name}类型')"
              field="sourceType"
              showKey="jydwSourceType"
            />
          </template>
        </tx-table-column-text> -->
        <!-- <tx-table-column-text
          :label="$dictValue('{name}类型')"
          v-if="show('jydwSourceType')"
        >
          <template slot-scope="scope">
            <tx-table-select
              :entity="scope.row"
              name="sourceType"
              :rules="formRules.sourceType"
              :prop="buildRowProp(scope, 'sourceType')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请输入{name}类型')"
              :options="{ values: pageData.jydwSourceType }"
            />
            <tx-table-select
              :entity="scope.row"
              name="sourceType"
              :rules="formRules.sourceType"
              :prop="buildRowProp(scope, 'sourceType')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请输入{name}类型')"
              :options="{ values: pageData.jydwSourceType }"
            />
          </template>
        </tx-table-column-text> -->
        <tx-table-column-text
          label="救援队伍类型"
          v-if="show('jydwSourceType')"
        >
          <template slot-scope="scope">
            <tx-table-select
              :entity="scope.row"
              name="sourceType"
              :rules="formRules.sourceType"
              :prop="buildRowProp(scope, 'sourceType')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请选择救援队伍类型')"
              :options="{ values: pageData.sourceType }"
              type="arra"
            />
          </template>
        </tx-table-column-text>
        <tx-table-column-text
          label="主要救援能力"
          v-if="show('jydwMajorDuties')"
        >
          <template slot-scope="scope">
            <tx-table-select
              :entity="scope.row"
              name="majorDuties"
              :rules="formRules.majorDuties"
              :prop="buildRowProp(scope, 'majorDuties')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请选择主要救援能力')"
              :options="{ values: pageData.dutyType }"
              type="arra"
            />
          </template>
        </tx-table-column-text>
        <tx-table-column-text
          label="辅助救援能力"
          v-if="show('jydwSecondaryDuties')"
          width="215"
        >
          <template slot-scope="scope">
            <tx-table-select
              multiple
              :entity="scope.row"
              name="secondaryDuties"
              :rules="formRules.secondaryDuties"
              :prop="buildRowProp(scope, 'secondaryDuties')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请选择辅助救援能力')"
              :options="{ values: pageData.dutyType }"
            />
          </template>
        </tx-table-column-text>

        <column
          :rules="formRules"
          :content="content"
          label="管理员姓名"
          field="name"
          showKey="jydwName"
          width="130"
        />
        <column
          :rules="formRules"
          :content="content"
          label="管理员职务"
          field="job"
          width="150"
          showKey="jydwJob"
        />
        <column
          :rules="formRules"
          :content="content"
          label="手机号"
          field="phone"
          width="150"
          showKey="jydwPhone"
        />

        <!--  -->
        <column
          :rules="formRules"
          :content="content"
          :label="$dictValue('{name}名称')"
          field="orgName"
        />

        <!-- 防护目标  -->

        <tx-table-column-text
          label="防护目标类型"
          v-if="show('fhmbSourceType')"
        >
          <template slot-scope="scope">
            <!-- <tx-table-select
              :entity="scope.row"
              name="sourceType"
              :rules="formRules.sourceType"
              :prop="buildRowProp(scope, 'sourceType')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请选择防护目标类型')"
              :options="{ values: pageData.sourceType }"
              v-if="pageData.sourceType?.length"
            /> -->
            <span >
              {{ tabs.activeName }}
            </span>
            <!-- <column-jydw-source-type
              :row="scope.row"
              :rules="formRules"
              :content="content"
              :label="$dictValue('{name}类型')"
              field="sourceType"
              showKey="hfmbSourceType"
            /> -->
          </template>
        </tx-table-column-text>

        <!-- <template slot-scope="scope">
            <tx-table-select
              :entity='scope.row'
              name="sourceType"
              :rules="formRules.sourceType"
              :prop="buildRowProp(scope, 'sourceType')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请输入{name}类型')"
              :options="{ values: pageData.fhmbSourceType }"
            />
          </template> -->

        <tx-table-column-text
          :label="$dictValue('{name}类型')"
          v-if="show('bncsSourceType')"
        >
          <template slot-scope="scope">
            <!-- <tx-table-select
              :entity="scope.row"
              name="sourceType"
              :rules="formRules.sourceType"
              :prop="buildRowProp(scope, 'sourceType')"
              :action="scope.row.$action"
              :placeholder="$dictValue('请输入{name}类型')"
              :options="{ values: pageData.sourceType }"
            /> -->
            <span >
              {{ tabs.activeName }}
            </span>
          </template>
        </tx-table-column-text>
        <column
          :rules="formRules"
          :content="content"
          label="管理员姓名"
          field="name"
        />
        <column
          :rules="formRules"
          :content="content"
          label="管理员职务"
          field="job"
        />
        <column
          :rules="formRules"
          :content="content"
          label="手机号"
          field="phone"
        />

        <tx-table-column-action width="230" align="left" :key="$columnKey()">
          <template slot-scope="scope">
            <el-form
              :ref="`form${scope.scope.scope.$index}`"
              :model="form.record"
              :rules="formRules"
              style="display: none"
            >
              <tx-form-input
                :entity="form.record"
                :name="item"
                v-for="(item, i) in content.field"
                :key="i"
              />
            </el-form>
            <el-button
              type="primary"
              size="mini"
              v-if="scope.row.$action != 'modify'"
              class="table-edit-btn"
              @click="handleEdit(scope)"
              >编辑
            </el-button>
            <el-button
              type="primary"
              size="mini"
              v-if="
                scope.row.id &&
                scope.row.$action != 'modify' &&
                getParameter('menuId') != '1000000013'
              "
              class="table-edit-btn"
              @click="handleDetailGo(scope)"
              >详情
            </el-button>
            <el-button
              type="primary"
              size="mini"
              v-if="scope.row.$action == 'modify'"
              @click="handleSave(scope)"
              class="table-save-btn"
              v-preventReClick="3000"
              >保存
            </el-button>
            <el-button
              size="mini"
              type="warning"
              v-if="scope.row.$action == 'modify'"
              @click="handleCancel(scope)"
              class="table-cancel-btn"
              >取消
            </el-button>
            <tx-button-text-delete
              class="table-del-btn"
              v-if="
                scope.row.$action == 'modify' &&
                content.deleteController == 'OrgController'
              "
              :controller="content.deleteController"
              :success="$handleQuery"
              target="记录"
              :body="{ id: scope.row.id, orgId: scope.row.orgId }"
            />

            <tx-button-text-delete
              class="table-del-btn"
              v-if="
                scope.row.$action == 'modify' &&
                ['UserController', 'AdminController'].includes(
                  content.deleteController
                )
              "
              :controller="content.deleteController"
              :success="$handleQuery"
              target="记录"
              idKey="id"
              :idValue="scope.row.id"
            />
          </template>
        </tx-table-column-action>
      </tx-list-table>
      <!-- {{
        $nextTick(() => {
          $initDragTable($refs["listTable"], table.page, "records");
        })
      }} -->
    </el-form>
    <validate-phone
      @success="SubmitEvent"
      :form="form.record"
      ref="validatePhone"
    ></validate-phone>
  </div>
</template>
<script>
import pageData from "./default.json";

import Column from "../column/column.vue";
import ColumnJydwSourceLevel from "../column/column-jydw-source-level.vue";
import ColumnJydwSourceType from "../column/column-jydw-source-type.vue";

export default {
  props: {
    active: {
      type: [String],
      default: "",
    },
    name: {
      type: [String],
      default: "",
    },
    dict: {
      type: Object,
      default() {
        return {};
      },
    },
    content: {
      type: Object,
      default() {
        return {
          controller: null,
          props: {},
          columns: [],
        };
      },
    },
  },
  data() {
    return {
      tabs: {
        //防护目标菜单tab切换
        active: "",
        activeName: "",
        list: [
          // {
          //   name: "tab1",
          //   number: 2,
          //   label: "tab1",
          // },
          // {
          //   name: "tab2",
          //   number: 2,
          //   label: "tab2",
          // },
        ],
      },
      allowSort: false,
      pageData: {
        sourceType: "",
      },
      table: {
        loading: false,
        query: {},
        sort: {
          descs: ["updateTime"],
        },
        page: this.$yzvue.initPage(),
      },
      // dict: dicts[this.name],
      initData: {
        $checkAll: false,
        $checked: [],
        $isIndeterminate: false,
        $sourceLevel: undefined,
        $visible: false,
        areaCode: "150000000000",
        areaName: "内蒙古自治区",
        city: "",
        cityOrgId: "",
        cityOrgName: "",
        country: "86",
        county: "",
        countyOrgId: "",
        countyOrgName: "",
      },
      form: {
        record: {
          name: "",
          resourceType: "",
          sourceTypeValue: "",
          majorDuties: [""],
          secondaryDuties: "",
          sourceType: [""],
          sourceLevel: {},
          orgName: "",
          job: "",
          phone: "",
          superiorOrgName: "",
          officeAddress: "",
          jobLevel: [""],
          userLevel: [""],
          desc: "",
        },
        records: [],
      },
      formRules: {
        name: this.$rule.name("姓名", null, 32),
        resourceType: this.$rule.requireds("类型不允许为空"),
        sourceType: this.$rule.requireds("类型不允许为空"),
        majorDuties: this.$rule.requireds("主要救援地址不允许为空", null, 200),
        secondaryDuties: this.$rule.requireds(
          "辅助救援能力不允许为空",
          null,
          200
        ),
        sourceLevel: this.$rule.requireds("级别不允许为空"),
        jobLevel: this.$rule.requireds("级别不允许为空"),
        orgName: this.$rule.name("单位", null, 32),
        job: this.$rule.name("职务", null, 32),
        phone: this.$rule.mobile("手机号", true),
        officeAddress: this.$rule.name("单位地址", null, 200),
        workUnit: this.$rule.name("所在单位", null, 32),
        desc: this.$rule.name("特长描述", null, 200),
      },
    };
  },
  components: {
    Column,
    ColumnJydwSourceLevel,
    ColumnJydwSourceType,
  },
  watch: {
    active: {
      handler(n, o) {
        if (n && n == this.name) {
          this.loadTable();
        }
      },
    },
  },

  mounted() {
    if (this.active == this.name) {
      this.getOrgType(this.getParameter("menuId"));
      this.loadTable();
    }
    // 辅助能力下拉框 
    if (this.getParameter("menuId") == "1000000010") {
      this.$api.OrgController.duty({}, (res) => {
        if (res.code == 0) {
          res.data = res.data.map((i, v) => {
            return {
              label: i,
              value: i,
            };
          });
          this.pageData.dutyType = res?.data;
        }
      });
    }
    // 专家
    if(this.getParameter("menuId") == "1000000013") {
      this.pageData.expertUserLevel = pageData.expertUserLevel
      this.pageData.expertJobLevel = pageData.expertJobLevel
    }
    //预设机构标签查询
    this.getYsTabs();
  },

  methods: {
    getYsTabs() {
      this.$api.OrgController.source(
      {
        body: {
          menuID: this.getParameter("menuId") || "150000000000",
          orgId: this.$currentUserInfo?.superiorOrg || this.$userInfo.superiorOrg,
        },
      },
      async (res) => {
        if (res.code == 0) {
          this.oneObjs = res.data.preSetSources;
          // 防护目标 避难场所/特殊处理
          // debugger
          if (this.getParameter("menuId") == "1000000012" || this.getParameter("menuId") == "1000000014") {
            this.tabs.list = this.oneObjs.map((item) => {
              return {
                label: item.name,
                name: item.id,
                mount: item.mount
              };
            });
            this.tabs.active = this.oneObjs[0]?.["id"];
            this.tabs.activeName = this.oneObjs[0]?.["name"];
            await this.getOrgType(this.tabs.active, "");
            this.loadTable();
          }
        }
      }
    );
    },
    async changeTab() {
      await this.getOrgType(this.tabs.active, "");
      this.tabs.activeName = this.oneObjs.filter(
        (i) => i.id == this.tabs.active
      )[0]["name"];
      this.loadTable();
    },
    getOrgType(parId, typelist) {
      if (!parId) {
        return false;
      }
      // 获取类型列表
      let data = {
        body: {
          parId,
        },
      };
      this.$api.OrgController.type(data, (res) => {
        if (res.code == 0) {
          res.data = res.data.map((i, v) => {
            return {
              label: i.name,
              value: i.id,
            };
          });
          this.pageData.sourceType = res?.data;
        }
      });
    },
    show(column) {
      return this.$in(column, this.content.columns);
    },
    handlePageChange(size, current) {
      this.loadTable(null, size, current);
    },

    handleNew() {
      Object.keys(this.form.record).forEach((v) => {
        if (v != "sourceType" && v != "jobLevel" && v != "userLevel")
          this.form.record[v] = "";
      });
      this.form.record.sourceType = [];
      this.form.record.majorDuties = [];
      let newRow = this.$lodash.cloneDeep({
        ...this.form.record,
        $action: "modify",
      });
      this.table.page.records.push({ ...newRow, ...this.initData });
      console.log(this.table);
    },

    handleQuery() {
      this.loadTable();
    },

    controller(name) {
      if (name == "list") return this.$api[this.content.listController];
      if (name == "update") return this.$api[this.content.updateController];
      if (name == "new") return this.$api[this.content.newController];
      if (name == "delete") return this.$api[this.content.deleteController];
    },

    loadTable() {
      let param = this.$handleQueryParam();
      param.body.sourceId = this.tabs.active;
      param.body.createdBy =
        this.$currentUserInfo?.phone || this.$userInfo.phone;
      param.body.orgId = this.$currentUserInfo?.orgId || this.$userInfo.orgId;
      (param.body.isLeader = this.content.dict.isLeader),
        (this.table.loading = true);
      this.controller("list").list(param, (res) => {
        this.table.loading = false;
        console.log("data", res);
        for (let ri = 0; ri < res.data.length; ri++) {
          const re = res.data[ri];
          re.secondaryDuties = re.secondaryDuties?.[0]
            ? re.secondaryDuties
            : "";
          re.$action = "view";
          re.$visible = false;
          re.$checked = [];
          re.$checkAll = false;
          re.$isIndeterminate = false;
        }
        // if(Array.isArray(res.data[0].sourceType)) {
        //   res.data[0].sourceType = res.data[0].sourceType[0]
        // }
        // 防护目标特殊处理
        // if (this.getParameter("menuId") == "1000000012") {
        //   res.data.forEach((i, j) => {
        //     i.sourceType = i.sourceType[1]
        //       ? [i.sourceType[1]]
        //       : [i.sourceType[0]];
        //   });
        // }
        this.$yzvue.assembleBody(this.table.page, { records: res.data });
        this.form.records = res.data;

        // this.$nextTick(() => {
        //   this.$initDragTable(
        //     this.$refs["listTable"],
        //     this.table.page,
        //     "records"
        //   );
        // });
      });
    },

    buildRowProp($scope, field) {
      let {
        scope: { scope },
      } = $scope;
      return `records.${scope.$index}.${field}`;
    },

    // 编辑
    handleEdit($scope) {
      if($scope.row.sourceType&&$scope.row.sourceType?.length>0) {
        $scope.row.sourceType = $scope.row.sourceType[1]
        ? [$scope.row.sourceType[1]]
        : [$scope.row.sourceType[0]];
      }

      $scope.row.$action = "modify";
      $scope.row.$origin = this.$lodash.pick($scope.row, this.content.fields);
    },
    // 保存
    handleSave($scope) {
      Object.assign(this.form.record, $scope?.row || {});
      let { id, name, orgName, job, workUnit, phone, udOrder } =
        this.form.record;
      this.$handleFormValidate(`form${$scope.scope.scope.$index}`, async () => {
        // 专家成员，弹窗验证码确认
        if (
          (($scope.row.id && $scope.row.$origin.phone != phone) ||
            !$scope.row.id) &&
          this.getParameter("menuId") == "1000000013"
        ) {
          //新增或者编辑状态下有修改手机号，则弹窗校验手机号
          let res = await this.$existPeople(id, phone);
          if (res?.data) {
            this.$refs.validatePhone.init();
            return false;
          } else {
            this.SubmitEvent($scope);
          }
        } else {
          this.SubmitEvent($scope);
        }
      });
    },
    // 提交数据
    SubmitEvent($scope) {
      let { id, phone, udOrder } = this.form.record;
      this.$handleFormValidate(`form${$scope.scope.scope.$index}`, async () => {
      //   // 专家成员
      //   if (this.getParameter("menuId") == "1000000013") {
      //     let res = await this.existPeople(id, phone);
      //     if (res?.data) {
      //       let managerInfo = res?.data?.phone ? `(${res?.data?.name},${res?.data?.phone})`:""
      //       this.$confirm(
      //         `手机号码${phone}已被注册,请联系${res?.data?.orgName}管理员${managerInfo}删除该手机账号后再添加!`,
      //         "提示",
      //         {
      //           confirmButtonText: "确定",
      //           type: "warning",
      //         }
      //       );
      //       return false;
      //     }
      //   }

      let pack = {
        body: this.$lodash.pick(this.form.record, [
          "id",
          ...this.content.fields,
        ]),
      };

      let isModify = pack.body.id;
      // if (!isModify) {
      Object.assign(pack.body, {
        menuID: this.getParameter("menuId"),
        areaCode: this.$userInfo.areaCode,
        createdBy: this.$userInfo.phone,
        orgId: this.$currentUserInfo?.orgId || this.$userInfo.orgId,
        pageType: this.$userInfo.pageType,
        udOrder: udOrder ? udOrder : this.table.page?.records.length,
      });
      // 防护目标特殊处理
      if (this.getParameter("menuId") == "1000000012" || this.getParameter("menuId") == "1000000014") {
        // pack.body.sourceType = this.pageData.sourceType?.length
        //   ? [this.tabs.active, pack.body.sourceType[0]]
        //   : [this.tabs.active];
        pack.body.sourceType = [this.tabs.active]
      }
      // }
      this.table.loading = true;
      let newMethod = this.controller("new").new;
      let updateMethod = this.controller("update").update;
      this.$invokeSave(pack, "id", newMethod, updateMethod, (res) => {
        this.table.loading = false;
        if (res && res.data) {
          this.getYsTabs();
          this.loadTable();
          this.form.record.$action = "view";
          if (!isModify) {
            this.form.record.id = res.data;
          }
        }
      });
      });
    },
    // 取消
    handleCancel($scope) {
      Object.assign($scope.row, $scope.row.$origin);
      $scope.row.$action = "view";
      this.$refs["form"].clearValidate();
    },
    //删除
    handleDelete($scope) {
      let {
        scope: { scope },
      } = $scope;
      this.table.page.records.splice(scope.$index, 1);
      // 请求后台接口删除数据库数据
    },
    updateSort() {
      if (this.allowSort == false) {
        this.$initDragTable(
          this.$refs["listTable"],
          this.table.page,
          "records"
        );
        this.beforeSortData = JSON.parse(
          JSON.stringify(this.table.page.records)
        );
      } else {
        let sortController = this.content.sortController;
        let params = this.table.page.records
          ?.filter((i) => (sortController == "OrgController" ? i.orgId : i.id))
          ?.map((i, k) => {
            return {
              id: sortController == "OrgController" ? i.orgId : i.id,
              udOrder: k + 1,
            };
          });
        this.$api[this.content.sortController].sort({ body: params }, (res) => {
          if (res.code == 0) {
            this.loadTable();
            this.$stopDragTable();
          }
        });
      }
      this.allowSort = !this.allowSort;
    },
    cancelSort() {
      this.allowSort = !this.allowSort;
      // this.this.table.page.records = JSON.parse(JSON.stringify(this.beforeSortData))
      // this.$initDragTable(this.$refs["listTable1"],
      //       this.table.page,
      //       "records1")
      this.$stopDragTable();
      this.loadTable();
    },
    handleDetailGo(scope) {
      // 点击详情按钮，如果是资源列表管理员，则调资源详情，如果是事业单位管理员，则逐级查看详情
      let mapMenuId = {
        1000000010: "TeamAdministrator",
        1000000011: "addMaterialWarehouse",
        1000000012: "protectionTargetAdministrator",
        1000000014: "maintenanceInformation",
      };
      if (this.getParameter("menuId") == "1000000008") {
        // 事业单位
        this.handleLevelDetail(scope);
      } else {
        // 资源管理员列表
        let row = scope.row;
        this.$router.push(
          `/${mapMenuId[this.getParameter("menuId")]}?depId=${row.orgId}`
        );
      }
    },
  },
};
</script>

<style lang="scss" scope>
$car-table-border-color: #e4e4e4;
$car-table-title-color: #f5f5f5;
.manager-list .el-tabs__item.is-active .tx-tab__label {
    -webkit-box-shadow: inset 0px 0px 10px #38c3c6;
    box-shadow: inset 0px 0px 10px #19e8d9;
    background: #5ed2e4;
}
.manager-list-tab-panel {
  .tx-list-query {
    margin: 0px;

    // border: 2px solid $c-bd-menu;
  }
  .tx-block {
    width: auto;
    margin: 15px 0px;
    background-color: $c-bg-query;
    border: 1px solid $c-bd-content;
  }

  .el-table td.el-table__cell {
    padding: 8px 0px 0px 0px;
    .cell > span {
      display: block;
      padding-bottom: 13px;
      line-height: 30px;
    }
    .tx-table-column-action {
      display: block;
      padding-bottom: 10px;
    }

    .el-input__inner {
      height: 30px;
      line-height: 30px;
      padding: 0px 5px;
    }
    .el-form-item {
      margin-bottom: 13px;
    }
    .el-form-item__content {
      line-height: 30px;
    }
    .el-form-item__error {
      padding-top: 0px;
    }
  }
}
.btnbox-right {
  display: flex;
  align-items: center;
  float: right;
  .tooltip {
    margin-left: 10px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    background: url("~@/assets/TeamAdministrator/icon_explain.png") no-repeat;
  }
}
</style>
